
public class OpenFile2 {

   public static Translator getTranslator(String fileType) {
      try {
         if (fileType.equals("doc")) {
            return (Translator)Class.forName("WordTranslator").newInstance();
         } else if (fileType.equals("html")) {
            return (Translator)Class.forName("HTMLTranslator").newInstance();
         } else if (fileType.equals("txt")) {
            return (Translator)Class.forName("PlainTranslator").newInstance();
         } else if (fileType.equals("xml")) {
            return (Translator)Class.forName("XMLTranslator").newInstance();
         } else {
            return new DefaultTranslator();
         }
      } catch (Exception e) {
         return new DefaultTranslator();
      }
   }

   public static void main(String[] args) {
      for (int i = 0; i < 100; i++) {
         System.out.println(getTranslator("txt"));
      }

   }

}

